home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.lzh / apndx11.prf < prev    next >
Text File  |  1987-06-23  |  4KB  |  192 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!            Begin Appendix 11
  18. .!
  19. .!***************************************************************************
  20. .!
  21. .!
  22. .AP XI Sample Code for Part XV
  23. /*------------------------------*/
  24. /*    includes        */
  25. /*------------------------------*/
  26.  
  27. #include "portab.h"                /* portable coding conv    */
  28. #include "machine.h"                /* machine depndnt conv    */
  29. #include "osbind.h"                /* BDOS defintions    */
  30. #include "gemdefs.h"
  31.  
  32. /*------------------------------*/
  33. /*    open_file         */
  34. /*------------------------------*/
  35.     WORD
  36. open_file(file_name)
  37.     BYTE    *file_name;
  38.     {
  39.     LONG    dos_hndl;
  40.  
  41.     FOREVER
  42.         {
  43.         dos_hndl = Fopen(file_name, 0);
  44.         if (dos_hndl >= 0)
  45.             return ((WORD) dos_hndl);
  46.         if ( !dos_error((WORD) dos_hndl) )
  47.             return (-1);
  48.         }
  49.  
  50.     return (-1);        /* Appease lint */
  51.     }
  52. .bp
  53. /*------------------------------*/
  54. /*    create_file         */
  55. /*------------------------------*/
  56.     WORD
  57. create_file(file_name)
  58.     BYTE    *file_name;
  59.     {
  60.     LONG    dos_hndl;
  61.  
  62.     FOREVER
  63.         {
  64.         dos_hndl = Fcreate(file_name, 0);
  65.         if (dos_hndl >= 0)
  66.             return ((WORD) dos_hndl);
  67.         if ( !dos_error((WORD) dos_hndl) )
  68.             return (-1);
  69.         }
  70.  
  71.     return (-1);        /* Appease lint */
  72.     }
  73. .bp
  74. /*------------------------------*/
  75. /*    dos_error         */
  76. /*------------------------------*/
  77.     WORD
  78. dos_error(tos_err)
  79.     WORD    tos_err;
  80.     {
  81.     WORD    f_ret;
  82.  
  83.     graf_mouse(ARROW, 0x0L);
  84.     if (tos_err > -50)
  85.         {
  86.         tos_err += 31;
  87.         tos_err = -tos_err;
  88.         }
  89.     f_ret = form_error(tos_err);
  90.     return (f_ret);
  91.     }
  92. .bp
  93. /*------------------------------*/
  94. /*    get_file         */
  95. /*------------------------------*/
  96.     WORD
  97. get_file(extnt, got_file)
  98.     BYTE    *extnt, *got_file;
  99.     {
  100.     WORD    butn, ii;
  101.     BYTE    tmp_path[64], tmp_name[13];
  102.  
  103.     tmp_name[0] = '\0';
  104.     tmp_path[0] = '\0';
  105.  
  106.     if (*got_file)
  107.         parse_fname(got_file, tmp_path, tmp_name, extnt);
  108.     if (!tmp_path[0])
  109.         get_path(&tmp_path[0], extnt);
  110.  
  111.     fsel_input(tmp_path, tmp_name, &butn);
  112.     if (butn)
  113.         {
  114.         strcpy(got_file, tmp_path);
  115.         for (ii = 0; got_file[ii] && got_file[ii] != '*'; ii++);
  116.         got_file[ii - 1] = '\0';
  117.         strcat (got_file, "\\");
  118.         strcat(got_file, tmp_name);
  119.         return (TRUE);
  120.         }
  121.     else
  122.         return (FALSE);
  123.     }
  124. .bp
  125. /*------------------------------*/
  126. /*    parse_fname         */
  127. /*------------------------------*/
  128.     VOID
  129. parse_fname(full, path, name, extnt)
  130.     BYTE    *full, *path, *name, *extnt;
  131.     {
  132.     WORD    i, j;
  133.     BYTE    *s, *d;
  134.  
  135.     for (i = strlen(full); i--; )        /* scan for end of path */
  136.         if (full[i] == '\\' || full[i] == ':')
  137.             break;
  138.     if (i == -1)
  139.         strcpy(name, full);        /* "Naked" file name */
  140.     else
  141.         {
  142.         strcpy(name, &full[i+1]);
  143.         for (s = full, d = path, j = 0; j++ < i + 1;
  144.             *d++ = *s++);
  145.         strcpy(&path[i+1], "*.");
  146.         strcat(path, extnt);
  147.         }
  148.     }
  149. .bp
  150. /*------------------------------*/
  151. /*    get_path         */
  152. /*------------------------------*/
  153.     VOID
  154. get_path(tmp_path, spec)
  155.     BYTE    *tmp_path, *spec;
  156.     {
  157.     WORD    cur_drv;
  158.  
  159.     cur_drv = Dgetdrv();
  160.     tmp_path[0] = cur_drv + 'A';
  161.     tmp_path[1] = ':';
  162.     Dgetpath(&tmp_path[2], 0);
  163.     if (strlen(tmp_path) > 3)
  164.         strcat(tmp_path, "\\");
  165.     else
  166.         tmp_path[2] = '\0';
  167.     strcat(tmp_path, "*.");
  168.     strcat(tmp_path, spec);
  169.     }
  170. .bp
  171. /*------------------------------*/
  172. /*    new_ext         */
  173. /*------------------------------*/
  174.     VOID
  175. new_ext(o_fname, n_fname, ext)
  176.     BYTE    *o_fname, *n_fname, *ext;
  177.     {
  178.     WORD    ii, jj;
  179.  
  180.     strcpy(n_fname, o_fname);
  181.     for (ii = (jj = strlen(n_fname)) - 1; ii && n_fname[ii] != '.'; ii--);
  182.     if (!ii)
  183.         n_fname[ii = jj] = '.';
  184.     strcpy(&n_fname[++ii], ext);
  185.     }
  186. .!
  187. .!****************************************************************************
  188. .!
  189. .!            End Appendix 11
  190. .!
  191. .!****************************************************************************
  192.